//测试 pthread_detach函数

#include <stdio.h>
#include <pthread.h>
#include <error.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
//子线程入口函数
void* start_routine(void* args)
{
    // sleep(3);
    return (void*)1111;
}
int main()
{
    pthread_t tid;
    int err = pthread_create(&tid, NULL, start_routine, NULL);
    if(err)
    {
        error(1, err, "pthread_create");
    }
    err = pthread_detach(tid);
    if(err)
    {
        fprintf(stderr, "pthread_detch is fail\n");
    }
    int ret; 
    err = pthread_join(tid, (void*)&ret);
    if(err)
    {
        error(1, err, "pthread_join");
    }
    printf("main pthread: 0x%lx termianted\n", tid);
    printf("retval : %d\n", ret);
    return 0;
}